package com.taotao.tools.mybatis.plugins.sass;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;

import java.util.Properties;

@Slf4j
@Intercepts({
        @Signature(type = Executor.class, method = "commit",
                args = {boolean.class}),
        @Signature(type = Executor.class, method = "rollback",
                args = {boolean.class}),
})
public class SassCommitRollbackInterceptor implements Interceptor {



    @Override
    public Object intercept(Invocation invocation) throws Throwable {

        TenantIdHelper.clearTenantId();

        return invocation.proceed();
    }


    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
    }



}